package com.qire.manhua.model.viewModel.impl;

import android.view.View;

import com.qire.common.constant.TeensModeManage;
import com.qire.common.support.base.BaseViewModel;
import com.qire.common.support.base.IViewModel;
import com.qire.manhua.BR;
import com.qire.manhua.R;
import com.qire.manhua.dal.service.TeensModeService;

import androidx.lifecycle.MutableLiveData;

public class TeensControlPanelViewModel extends BaseViewModel implements IViewModel {

    private TeensModeService teensService = new TeensModeService();

    @Override
    public int getVariableId() {
        return BR.teensControlPanelViewModel;
    }

    //region    #附加管理 begin
    /**
     * 清理函数，在Activity退出时，ViewModel生命周期到期会被回收，调用该事件，
     * 页面由于切换、横竖屏转换、内存回收等情况并不会影响到ViewModel的生命周期。
     */
    @Override
    protected void onCleared() {
        super.onCleared();
        this.teensService = null;
    }
    //endregion #附加管理 end

    // region #业务数据访问

    public void queryTeensModeState() {
        teensService.queryTeensModeState();
    }

    // endregion

    // region #UI操作
    public void refreshStatePanelUI() {
        final boolean enable = TeensModeManage.teensModeEnable();
        set("umbrellaRid", enable ? R.drawable.app_teens_icon_umbrella_enable : R.drawable.app_teens_icon_umbrella_disable);
        set("stateText", enable ? "青少年模式已开启" : "青少年模式未开启");
        set("enableStateVisible", enable ? View.VISIBLE : View.GONE);
        set("disableStateVisible", enable ? View.GONE : View.VISIBLE);
    }
    // endregion

    // region #UI属性绑定

    public MutableLiveData<Integer> getUmbrellaRid() {
        return get("umbrellaRid");
    }
    public MutableLiveData<CharSequence> getStateText() {
        return get("stateText");
    }
    public MutableLiveData<Integer> getEnableStateVisible() {
        return get("enableStateVisible");
    }
    public MutableLiveData<Integer> getDisableStateVisible() {
        return get("disableStateVisible");
    }

    // endregion

}
